***produce figure 1; replication of Chetty map
use "$data/LOO/onlinedata5", clear
keep cz e_rank_b_8082
maptile e, geo(cz1990) stateoutline(medium) n(9) rev spopt(mos(thick)) legdecimals(1) ///
savegraph("$output/fig1_cz_mobility.png") replace
graph close


****make lifetime migration by age line plot (figure 3 in paper)
use "$data/ACS/usa_00002", clear
keep if year>=2010 //first decade of 21st century
keep if age>=5 & age<=80 //sensible age range
keep if bpl<100 //look at native-borns for now

//recode 1-year migration dummy for intrastate interpretation
drop if migrate1 == 0 | migrate1 == 4
replace migrate1 = 0 if migrate1 == 1 | migrate1 == 2
replace migrate1 = 1 if migrate1 == 3

tab school [w=perwt] if migrate1 == 1 & age == 18
tab school [w=perwt] if migrate1 == 1 & age == 19
tab school [w=perwt] if migrate1 == 1 & age == 20
tab school [w=perwt] if migrate1 == 1 & age == 21
tab school [w=perwt] if migrate1 == 1 & age == 22
tab school [w=perwt] if migrate1 == 1 & age == 23
tab school [w=perwt] if migrate1 == 1 & age == 24
tab school [w=perwt] if migrate1 == 1 & age == 25

gen mig_lifetime = (bpl!=statefip) //lifetiem migration flag
tab statefip if mig_lifetime, sort //most popular destinations

collapse (mean) mig_lifetime migrate1 [fweight = perwt], by(age)
su mig_lifetime if age>=36 & age<=54

//lifetime migration graph
twoway line mig_lifetime age, bgcolor(white) graphregion(color(white)) ytitle("Lifetime Migration Rate", size(large)) ///
xtitle("Age", size(large)) xlabel(0(6)78, labsize(medlarge)) ylabel(0(.1).5, labsize(medlarge))
graph export "$output/fig3_age_mig_lifetime.png", replace

twoway line migrate1 age, bgcolor(white) graphregion(color(white)) ytitle("1-Year Migration Rate", size(large)) ///
xtitle("Age", size(large)) xlabel(0(6)78, labsize(medlarge)) ylabel(0(.01).1, labsize(medlarge))
graph export "$output/fig3_age_mig_year.png", replace
graph close

//end of do-file

